<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DOMParse对象读取xml的文件</title>
</head>

<body>
  <input id="result" type="file" value="点击我">
  <div id="dv"></div>
</body>
<script>
  "use strict"; {
    const dv = document.getElementById("dv");
    document.querySelector("#result").addEventListener("change", (e) => {
      let first_res = e.target.files[0];
      let parse = new DOMParser(); //声明读取xml对象,也可以读取html的文件,得要传入类型
      let doc = parse.parseFromString(first_res, "text/html"); //最终生成dom对象
      console.log(doc);
      dv.innerHTML = doc;

      /* reader.addEventListener("load", (e) => {
      }); */
    });
  };
</script>

</html>